package com.epro.dx.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;

import com.epro.dx.R;

/**
 * 商品评论列表头部显示（包括商品名称，价格，运费及Review总数及平均分）
 * @author cw55072
 * @version  [1.0, 2010-10-13]
 */
public class ReviewListHeaderView extends LinearLayout
{
    
    private Context context;
    
    /**
     * 商品名，评论数
     */
    private TextView productName, reviewCount;
    
    /**
     * rating平均分
     */
    private RatingBar ratingBar;
    
    ImageView line;
    
    public ReviewListHeaderView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        initialize(context);
    }
    
    public ReviewListHeaderView(Context context)
    {
        super(context);
        initialize(context);
    }
    
    private void initialize(Context context)
    {
        this.context = context;
        View view = LayoutInflater.from(this.context).inflate(R.layout.review_list_header_view, null);
        productName = (TextView)view.findViewById(R.id.productNameText3);
        reviewCount = (TextView)view.findViewById(R.id.rating2);
        ratingBar = (RatingBar)view.findViewById(R.id.indicator_ratingbar2);
        line = (ImageView)view.findViewById(R.id.line);
        addView(view);
    }
    
    public void setImageView(int r)
    {
        line.setVisibility(r);
    }
    
    public void setProductNameView(String name)
    {
        productName.setText(name);
    }
    
    public void setReviewCountView(String count)
    {
        reviewCount.setText(count);
    }
    
    public void setRatingBarView(int r)
    {
        if (r > 0)
        {
            ratingBar.setNumStars(r);
            ratingBar.setRating(r);
        }
        else
        {
            ratingBar.setVisibility(View.GONE);
        }
    }
}